package com.audaque.springboot.foshanupload.web.nettydemo.listener;

import com.audaque.springboot.foshanupload.web.nettydemo.component.NettyServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * @author zgb
 * @desc ...
 * @date 2022-01-22 15:00:02
 */

@Component
@Slf4j
public class NettyDemoApplicationReadyEventListener implements ApplicationListener<ApplicationEvent> {

    @Autowired
    private NettyServer nettyServer;

    @Override
    public void onApplicationEvent(ApplicationEvent applicationEvent) {


        if (applicationEvent instanceof ApplicationReadyEvent) {
            log.debug("ApplicationReadyEvent:项目启动成功");

            try {
                //启动netty服务端
                nettyServer.start(9501);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

    }
}
